/* ptd.t   ITEM MASTER DELETE TRIGGER                                 */

TRIGGER PROCEDURE FOR DELETE OF PT_MSTR.

/*J12B  if not can-find(first whl_mstr where whl_mstr.whl_act no-lock) */
/*J12B  then leave. */

        {mfdeclre.i }
        define new shared work-table wf_old_pt_mstr like pt_mstr.
        define new shared variable w-recid as recid.
        define variable w-file as character format "x(24)".


        /* Warehousing Interface processing */

        WI:
        do:

        /* If there is no active external warehouse, then do not process */
/*K01B     and if the item extract flag is not set, then do not process  */
/*J12B*/    if not can-find(first whl_mstr no-lock
/*K01B /*J12B*/        where whl_mstr.whl_act) */
/*K01B*/           where whl_mstr.whl_act
/*K01B*/           and whl_mstr.whl_pt_exp)
/*J12B*/    then leave WI.

        /* Move key pt_mstr values to work table for subsequent processing */
            assign w-recid = recid(pt_mstr).
            create wf_old_pt_mstr.
            if recid(wf_old_pt_mstr)= -1 then.
            assign
                wf_old_pt_mstr.pt_part       = pt_mstr.pt_part.

        /* Call subprogram to create export transactions for warehouses */
            w-file = "wiptd.p".
/*J1DM*/ /* {gprun.i ""wiptd.p""} */
/*J1DM*/    {gprunmo.i &module="WI"
                       &program="wiptd.p"}

/*J12B*/end. /* WI */


HK:
do:
    if can-find(first dt_mstr where dt_table = "pt_mstr" and dt_type = "SYNC") then
        run CreateSyncFlag(input "DEL", input recid(pt_mstr), input "pt_mstr").

    if not can-find ( first dt_mstr where dt_table = "pt_mstr" and dt_type = "DEL" ) then leave HK.
    
    if not can-find ( first wf_old_pt_mstr ) then do:
        create wf_old_pt_mstr.
        if recid(wf_old_pt_mstr)= -1 then .
    end.
    
    buffer-copy pt_mstr to wf_old_pt_mstr no-error.

    for first dt_mstr no-lock where dt_table = "pt_mstr" and dt_type = "DEL" :
    
        run CreateDthist(input dt_table, input dt_field, input dt_type, input "", input "", 
            input recid(pt_mstr), input pt_mstr.pt_part, input "", input "", input "",
            input "", input "", input "", input "") .
            
    end.
end.

{hkdttrans.i}
